package com.test.mylotterysystem.dao.Mapper;

import com.test.mylotterysystem.dao.DO.Encrypt;
import com.test.mylotterysystem.dao.DO.UserDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select count(*) from user where user_name = #{name}")
    int checkUserName(String name);

    @Select("select count(*) from user where email = #{mail}")
    int checkUserMail(String mail);

    @Select("select count(*) from user where phone_number = #{phoneNumber}")
    int checkPhone(String phoneNumber);

    @Insert("insert into user (user_name, email, phone_number, password, identity) " +
            "values (#{userName},#{email},#{phoneNumber},#{password},#{identity})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void insertUserInfo(UserDO userDO);

    @Select("select * from user where phone_number = #{phoneNumber};")
    UserDO selectByPhoneNumber(Encrypt phoneNumber);

    @Select("<script>" +
            "select * from user " +
            "<where>" +
            "  <if test='identity != null'>identity = #{identity}</if>" +
            "</where>" +
            "order by id desc" +
            "</script>")
    List<UserDO> getUserInfoList(String identity);

    @Select("<script> " +
            "select id from user where id in" +
            " <foreach item='item' collection='usersId' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            "</script>")
    List<Long> selectByUsersId(List<Long> usersId);
}
